package com.offen.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.offen.entity.Student;
import com.offen.service.IStudentService;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import javax.xml.transform.Result;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author lishucai
 * @since 2022-06-17
 */

@RestController
@RequestMapping("/st")
public class StudentController {

    @Resource
    private IStudentService studentService;

    //获取所有用户
    @GetMapping
    public List<Student> getUuser() {
        List<Student> students = studentService.list();
        return students;
    }

    //添加学生
    @PostMapping("/u")
    public boolean add(@RequestBody Student Str) {
        boolean b = studentService.save(Str);
        return b;
    }

    //删除学生，并且删除对应的课程关系
    @RequestMapping("/delete")
    public boolean delete(@RequestBody Student student) {
        boolean b = studentService.deleteStudent(student);
        return b;
    }

    //修改学生信息
    @PutMapping
    public Boolean update(@RequestBody Student ss) {
        return studentService.update(ss, studentService.update1(ss.getId()));
    }
    /**
     * 学生查询为分页条件查询，查询条件如下：
     *
     * 姓名：模糊查询
     * 性别：精确查询
     * 年级：精确查询 学生删除时，需要删除与课程的关联信息
     */
    @PostMapping("/select/{pageSize}/{pageNumber}")
    public Page<Student> selectStudentByName(@RequestBody Student student,
                                             @PathVariable Integer pageSize,
                                             @PathVariable Integer pageNumber){
        System.out.println("模糊查询");
        return studentService.selectStudent(student,pageSize,pageNumber);
    }
}
